package util.designpattern.proxyPattern;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

    /**
     * jdk动态代理实现方式
     */
    public class JDBMeipo implements InvocationHandler {

    //被代理的对象
    private Object object;
    public Object getInstance(Object object) {
        this.object = object;
        Class<?> clazz = object.getClass();
        return Proxy.newProxyInstance(clazz.getClassLoader(),clazz.getInterfaces(),this);
    }
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        before();
        Object obj = method.invoke(this.object,args);
        after();
        return obj;
    }


    private void before(){
        System.out.println("我是媒婆：？？？？？？？？？？？？？？？？");
    }

    private void after(){
        System.out.println("如果合适的话，准备办婚事");
    }
}
